home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / vector.lha / vector / stack.c < prev    next >
C/C++ Source or Header  |  1991-11-23  |  1KB  |  47 lines

  1. #include <stack.h>
  2. #include <osfcn.h>
  3.  
  4. // Push the CTM onto the stack; return success
  5. int MatrixStack::push() {
  6.     if (depth < MatrixStackDepth) {
  7.     stack[depth++] = tos;
  8.     adjointflag = 0;    // Adjoint not computed
  9.     return 1;
  10.     } else {
  11.     cerr << "MatrixStack::push(): stack full!" << endl;
  12.     return 0;
  13.     }
  14. }
  15.  
  16. // Pop the stack into the CTM; return success
  17. int MatrixStack::pop() {
  18.     if (depth > 0) {
  19.     tos = stack[--depth];
  20.     adjointflag = 0;    // Adjoint lost and needs to be recomputed
  21.     return 1;
  22.     } else {
  23.     cerr << "MatrixStack::pop(): stack empty!" << endl;
  24.     return 0;
  25.     }
  26. }
  27.  
  28. // Compute the adjoint & determinant of the CTM
  29. void MatrixStack::compute_adjoint() {
  30.     tosadjoint = adjoint(tos, &tosdeterminant);
  31.     adjointflag = 1;
  32. }
  33.  
  34. // Returns the adjoint of the CTM
  35. HMatrix &MatrixStack::ctmadjoint() {
  36.     if (!adjointflag)
  37.     compute_adjoint();
  38.     return tosadjoint;
  39. }
  40.  
  41. // Returns the determinant of the CTM
  42. float MatrixStack::ctmdet() {
  43.     if (!adjointflag)
  44.     compute_adjoint();
  45.     return tosdeterminant;
  46. }
  47.